package examples;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServerDemo02 {
    public static void main(String[] args) {

        try {
            ServerSocket serverSocket = new ServerSocket(6666);

            Socket socket = serverSocket.accept();

            InputStream in = socket.getInputStream();
            OutputStream outputStream = new FileOutputStream(new File("E:\\test.jpg"));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);

            int len = 0;
            byte[] bytes = new byte[1024];
            while ((len = in.read(bytes)) != -1) {
                outputStream.write(bytes, 0, len);
            }

            out.println("文件上传成功！");


        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
